<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>提醒事项</title>
  <style>
    body {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      margin: 0;
      background-color: #f0f0f0;
    }

    .reminder-container {
      width: 400px;
      border: 1px solid #ccc;
      border-radius: 5px;
      overflow: hidden;
    }

    .top-section {
      background-color: #ffdab9;
      padding: 20px;
    }

    .title {
      color: white;
      font-size: 24px;
      margin-bottom: 10px;
    }

    .add-box {
      display: flex;
    }

    .add-input {
      flex: 1;
      padding: 8px;
      border: none;
      border-radius: 3px 0 0 3px;
    }

    .add-button {
      padding: 8px 15px;
      background-color: #4caf50;
      color: white;
      border: none;
      border-radius: 0 3px 3px 0;
      cursor: pointer;
    }

    .bottom-section {
      background-color: white;
      padding: 20px;
    }

    .item {
      display: flex;
      align-items: center;
      padding: 10px 0;
      border-bottom: 1px solid #ccc;
    }

    .item:last-child {
      border-bottom: none;
    }

    .item-text {
      margin-right: auto;
    }

    .action-button {
      padding: 5px 10px;
      margin-left: 5px;
      border: none;
      border-radius: 3px;
      cursor: pointer;
    }

    .move-up,
    .move-down {
      background-color: #2196f3;
      color: white;
    }

    .delete {
      background-color: #ff9800;
      color: white;
    }

    .disabled {
      background-color: #ccc;
      cursor: not-allowed;
    }
  </style>
</head>

<body>
  <div class="reminder-container">
    <div class="top-section">
      <div class="title">提醒事项</div>
      <div class="add-box">
        <input type="text" class="add-input" placeholder="内容">
        <button class="add-button" onclick="addItem()">添加</button>
      </div>
    </div>
    <div class="bottom-section">
      <div class="item">
        <span class="item-text">1. 学习</span>
        <button class="action-button move-up" onclick="moveUp(this)">上移</button>
        <button class="action-button move-down" onclick="moveDown(this)">下移</button>
        <button class="action-button delete" onclick="deleteItem(this)">删除</button>
      </div>
      <div class="item">
        <span class="item-text">2. 睡觉</span>
        <button class="action-button move-up" onclick="moveUp(this)">上移</button>
        <button class="action-button move-down" onclick="moveDown(this)">下移</button>
        <button class="action-button delete" onclick="deleteItem(this)">删除</button>
      </div>
      <div class="item">
        <span class="item-text">3. 吃饭</span>
        <button class="action-button move-up" onclick="moveUp(this)">上移</button>
        <button class="action-button move-down" onclick="moveDown(this)">下移</button>
        <button class="action-button delete" onclick="deleteItem(this)">删除</button>
      </div>
    </div>
  </div>

  <script>
    function addItem() {
      const input = document.querySelector('.add-input');
      const value = input.value.trim();
      if (value) {
        const bottomSection = document.querySelector('.bottom-section');
        const items = bottomSection.querySelectorAll('.item');
        const newIndex = items.length + 1;
        const newItem = document.createElement('div');
        newItem.classList.add('item');
        newItem.innerHTML = `
          <span class="item-text">${newIndex}. ${value}</span>
          <button class="action-button move-up" onclick="moveUp(this)">上移</button>
          <button class="action-button move-down" onclick="moveDown(this)">下移</button>
          <button class="action-button delete" onclick="deleteItem(this)">删除</button>
        `;
        bottomSection.appendChild(newItem);
        input.value = '';
        updateButtonStates();
      }
    }

    function moveUp(button) {
      const item = button.parentNode;
      const prevItem = item.previousElementSibling;
      if (prevItem) {
        item.parentNode.insertBefore(item, prevItem);
        updateButtonStates();
      }
    }

    function moveDown(button) {
      const item = button.parentNode;
      const nextItem = item.nextElementSibling;
      if (nextItem) {
        item.parentNode.insertBefore(nextItem, item);
        updateButtonStates();
      }
    }

    function deleteItem(button) {
      const item = button.parentNode;
      item.parentNode.removeChild(item);
      updateButtonStates();
      updateItemIndexes();
    }

    function updateButtonStates() {
      const items = document.querySelectorAll('.item');
      items.forEach((item, index) => {
        const moveUpButton = item.querySelector('.move-up');
        const moveDownButton = item.querySelector('.move-down');
        moveUpButton.classList.remove('disabled');
        moveDownButton.classList.remove('disabled');
        if (index === 0) {
          moveUpButton.classList.add('disabled');
          moveUpButton.disabled = true;
        } else {
          moveUpButton.disabled = false;
        }
        if (index === items.length - 1) {
          moveDownButton.classList.add('disabled');
          moveDownButton.disabled = true;
        } else {
          moveDownButton.disabled = false;
        }
      });
    }

    function updateItemIndexes() {
      const items = document.querySelectorAll('.item');
      items.forEach((item, index) => {
        const itemText = item.querySelector('.item-text');
        const textParts = itemText.textContent.split('. ');
        itemText.textContent = `${index + 1}. ${textParts[1]}`;
      });
    }

    // 初始化按钮状态
    updateButtonStates();
  </script>
</body>

</html>